package com.hps.shiro.service.impl;

import com.hps.shiro.mapper.UserMapper;
import com.hps.shiro.model.User;
import com.hps.shiro.service.UserService;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @author heps
 * @since 2020/6/8 11:41
 */
@AllArgsConstructor
@Service
public class UserServiceImpl implements UserService {

  private final UserMapper userMapper;

  @Override
  public User findByUserName(String username) {
    Example example = new Example(User.class);
    Criteria criteria = example.createCriteria();
    criteria.andEqualTo("username", username);

    List<User> users = userMapper.selectByExample(example);
    if (CollectionUtils.isEmpty(users)) {
      return null;
    }
    return users.get(0);
  }

  @Override
  public int updateUser(User user) {
    return 0;
  }
}
